var editor;

//On Load Bind Ace to the editor
$(function() {editor = ace.edit("file_viewer");
  //No print margin
  editor.setShowPrintMargin(false);
});

//On change event
$("select").live("change", function() {
   //Get Editor
   editor = ace.edit("file_viewer");
   
   //Get the selected option
   var language = $(this).find("option:selected").text();
   
   //Append the right script to the head
   $('head').append('<script src="js/src/mode-'+ language +'.js" type="text/javascript" charset="utf-8"></script>');
   
   //Set up a new Mode
   var mode = require("ace/mode/" + language).Mode;
   editor.getSession().setMode(new mode());
   
   //Get file path and redisplay it -> Strange Behavior when changing language
   var path = $("#file_name").html();
   display_file(path);
   
   //No print margin
   editor.setShowPrintMargin(false);
});